package com.hadoop.project.mvc.controller.hbasecmp;

import com.hadoop.project.entity.constant.RedisComplexConstant;
import com.hadoop.project.mvc.controller.ABaseController;
import com.hadoop.project.entity.constant.PreProcessingDataModifier;
import com.hadoop.project.entity.hbase.*;
import com.hadoop.project.gen.maodaligendata.GenConstant;
import com.hadoop.project.mvc.service.hbase.HBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/hbase")
public class HBaseController extends ABaseController {

    @Autowired
    private HBaseService hBaseService;

    @Autowired
    private RedisComplexConstant x;

    @GetMapping("/getAll")
    public String getAll() throws Exception {
        String tableName = GenConstant.TableName;
        HBaseResult hBaseResult = hBaseService.getAll(tableName);

        // 如果需要处理数据
        if (PreProcessingDataModifier.needResolve) {
            hBaseResult = PreProcessingDataModifier.preProcessingData(hBaseResult);
        }

        List<Tab> tabList = hBaseResult.getTabList().stream().filter(e -> e.getTid() != null).collect(Collectors.toList());
        List<Video> videoList = hBaseResult.getVideoList().stream().filter(e -> e.getVid() != null).collect(Collectors.toList());
        List<HBaseUser> hBaseUserList = hBaseResult.getHBaseUserList().stream().filter(e -> e.getUid() != null).collect(Collectors.toList());
        List<UserLog> userLogList = hBaseResult.getUserLogList().stream().filter(e -> e.getId() != null).collect(Collectors.toList());


        for (Tab tab : tabList) {
            System.out.println(tab);
        }

        for (Video video : videoList) {
            System.out.println(video);
        }

        for (HBaseUser user : hBaseUserList) {
            System.out.println(user);
        }

        for (UserLog log : userLogList) {
            System.out.println(log);
        }

        // return videoList.toString();
        return videoList.toString();
    }
}
